<template>
  <div class="app-container">
    <basic-container>
      <avue-form ref="form"
                 v-model="obj"
                 :option="option">
        <template slot-scope="scope"
                  slot="menuForm">
          <el-button type="primary"
                     @click="isAdd?rowSave():rowUpdate()">{{isBtnText}}</el-button>
          <el-button type="primary"
                     @click="breaks">返回</el-button>
        </template>
      </avue-form>
    </basic-container>
  </div>
</template>

<script>
import { addObj, putObj, getById } from "@/api/vipManage/vipLevel";
const DIC = {
  flag: [
    {
      label: "是",
      value: "0"
    },
    {
      label: "否",
      value: "1"
    }
  ]
};
export default {
  data() {
    return {
      obj: {}
    };
  },
  created() {
    this.getObj();
  },
  computed: {
    isBtnText() {
      return this.isAdd ? "新增" : "修改";
    },
    isAdd() {
      return !this.$route.params.id;
    },
    option() {
      return {
        dicData: DIC,
        submitText: "提交",
        formWidth: "60%",
        submitBtn: false,
        emptyBtn: false,
        column: [
          {
            label: "等级",
            prop: "vipdj",
            span: 20
          },
          {
            label: "等级名称",
            prop: "name1",
            placeholder: "如黄金会员、钻石会员等",
            span: 20
          },
          {
            label: "条件",
            prop: "tj",
            prepend: "满多少积分成为该等级会员",
            append: "积分",
            span: 20
          },
          {
            labelWidth: 80,
            prop: "xffy",
            prepend: "消费",
            append: "元",
            span: 11
          },
          {
            labelWidth: 0,
            prop: "xffyjf",
            prepend: "等于",
            append: "积分",
            span: 9
          },
          {
            label: "折扣",
            prop: "zhekou",
            placeholder: "0~1之间的数字，如8.5折，填写 0.85",
            append: "折",
            span: 20
          },
          {
            label: "是否启用",
            prop: "flag",
            span: 20,
            type: "radio",
            dicData: "flag"
          }
        ]
      };
    }
  },
  methods: {
    getObj() {
      if (!this.isAdd) {
        getById(this.$route.params.id).then(res => {
          this.obj = res.data;
        });
      }
    },
    rowUpdate() {
      putObj(this.obj).then(() => {
        this.$message({
          showClose: true,
          message: "修改成功",
          type: "success"
        });
        this.$router.$avueRouter.closeTag();
        this.$router.push({ path: "/vipManage/vipLevel" });
      });
    },
    rowSave() {
      addObj(Object.assign({}, this.obj)).then(() => {
        this.$message({
          showClose: true,
          message: "添加成功",
          type: "success"
        });
        this.$router.$avueRouter.closeTag();
        this.$router.push({ path: "/vipManage/vipLevel" });
      });
    },
    breaks() {
      this.$router.$avueRouter.closeTag();
      this.$router.push({ path: "/vipManage/vipLevel" });
    }
  }
};
</script>

<style>
</style>